package com.weiyin.examination.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.weiyin.examination.R;
import com.weiyin.examination.adapter.TopicsAdapter;
import com.weiyin.examination.util.LayoutHelper;
import com.weiyin.examination.view.DividerItemDecoration;

import java.util.ArrayList;

/**
 * <pre>
 *     e-mail : niejunfeng@win-electr.com
 *     time   : 2018/04/04
 *     desc   :
 *     version: 1.0.0
 *     Copyright: Copyright（c）2017
 *     Company:上海蔚音电子科技有限公司
 * </pre>
 *
 * @author niejunfeng
 */
@SuppressLint("Registered")
public class QuestionTypeActivity extends BaseActivity implements TopicsAdapter.OnItemClickListener, View.OnClickListener {

    private RecyclerView recyclerView;
    ArrayList<String> stringData;
    private String name;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question_type);

        LayoutHelper layoutHelper = new LayoutHelper(this);
        layoutHelper.scaleView(findViewById(R.id.activityQuestionTypeLayout));

        name = getIntent().getStringExtra("name");
        initData();
        initView();
    }

    private void initData() {
        if (stringData == null) {
            stringData = new ArrayList<>();
        }
        for (int i = 0; i < 9; i++) {
            stringData.add("题型" + (i + 1));
        }
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        TopicsAdapter topicsAdapter = new TopicsAdapter(this, R.layout.topic_item_layout, stringData, "1");
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        TextView title = (TextView) findViewById(R.id.title);
        ImageView back = (ImageView) findViewById(R.id.back);
        title.setText(name);
        recyclerView.addItemDecoration(new DividerItemDecoration(
                this, DividerItemDecoration.VERTICAL_LIST, 3, getResources().getColor(R.color.CL)));

        recyclerView.setAdapter(topicsAdapter);
        topicsAdapter.setOnItemClickListener(this);
        back.setOnClickListener(this);
    }

    @Override
    public void onItemClick(BaseViewHolder baseViewHolder, int position, String type) {
        startActivity(new Intent(QuestionTypeActivity.this, PayActivity.class));
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            default:
                break;
        }
    }
}
